package com.androidRtc.controller;

import com.androidRtc.dao.UserDao;
import com.androidRtc.entity.Users;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class RegServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String username,password,telephone,email;
        UserDao dao = new UserDao();
        Users user = null;
        int result = 0;
        PrintWriter out = null;
        username = request.getParameter("username");
        password = request.getParameter("password");
        telephone = request.getParameter("telephone");
        email = request.getParameter("email");
        user = new Users(null,username,password,telephone,email);
        result = dao.add(user);
        response.setContentType("text/html;charset=utf-8");
        out = response.getWriter();
        if(result == 1){
            out.print("注册成功，请登录！");
            out.flush();
            out.close();
        }else{
            out.print("注册失败，请重试！");
            out.flush();
            out.close();
        }
    }
}
